﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Threading;
using System.Collections.ObjectModel;

// Toolkit namespace
using System.Windows.Input;
using SimpleMvvmToolkit;

// Toolkit extension methods
using SimpleMvvmToolkit.ModelExtensions;
using SpotTheMisspell.Models;

namespace SpotTheMisspell.ViewModels
{
    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// Use the <strong>mvvmprop</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// </summary>
    public class ResultPageViewModel : ViewModelBase<ResultPageViewModel>
    {
        private ObservableCollection<Word> _wordCollection;
        public ObservableCollection<Word> WordCollection
        {
            get { return _wordCollection; }
            set
            {
                _wordCollection = value;
                NotifyPropertyChanged(m => m.WordCollection);
            }
        }

       public ResultPageViewModel()
       {
           RegisterToReceiveMessages<List<Word>, bool>(MessageToken.GuessedWordList, OnViewShow);
       }

       void OnViewShow(object sender, NotificationEventArgs
        <List<Word>, bool > e)
       {
           if (_wordCollection == null)
           {
               _wordCollection = new ObservableCollection<Word>();
           }
           //clear the current word collection
           _wordCollection.Clear();
           foreach (var word in e.Data)
           {
               WordCollection.Add(word);
           }
           WordCollection = WordCollection;
           e.Completed(true);
       }
       public ICommand RestartNewGameCommand
       {
           get { return new DelegateCommand(RestartGame); }
       }



       private void RestartGame()
       {
           App.Navigator.Back();
           ;
       }

    }
}